package com.tjetc.Impl;

import com.tjetc.domain.Health;
import com.tjetc.domain.Newborn;
import com.tjetc.mapper.HealthMapper;
import com.tjetc.mapper.NewbornMapper;
import com.tjetc.service.NewBornService;
import com.tjetc.utils.Db;
import com.tjetc.vo.Result;

import java.util.List;

public class NewBornServiceImpl implements NewBornService {
    private NewbornMapper newbornMapper= Db.getMapper(NewbornMapper.class);
    private HealthMapper healthMapper=Db.getMapper(HealthMapper.class);
    private Result result=new Result();
    @Override
    public Result selBN(String x) {
        try {
            List<Newborn> newbornList=newbornMapper.selBN(x);
            if (newbornList==null){
                return result.setCode(500).setMsg("未查询到相关信息");
            }else {
                return result.setCode(200).setMsg("查询成功").setData(newbornList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.setCode(500).setMsg("查询失败");
    }

    @Override
    public Result addH(Health health) {
        try {
            int rows = healthMapper.insert(health);
            if (rows==-1){
                return result.setCode(500).setMsg("录入失败");
            }else {
                return  result.setCode(200).setMsg("录入成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result.setCode(500).setMsg("录入失败");
    }

    @Override
    public Newborn findNID(int newbornId) {
        return newbornMapper.selectByPrimaryKey(newbornId);
    }
    @Override
    public Newborn findBId(int id) {
        return newbornMapper.selectByPrimaryKey(id);
    }

    @Override
    public Newborn sel(int id) {
        return newbornMapper.selectByPrimaryKey(id);
    }
}
